package com.yanqu.road.logic.activity.foxcard.game.effect;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardShowType;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 弃掉x张指定牌 / 花色，可以获得金币, 每轮战斗点数随机
 * 点数|花色|筹码|乘筹码|倍率|乘倍率|金币
 */
public class FoxCardEffect54 extends FoxCardEffectBase {
    @Override
    protected void effectHandle(FoxCardGameLogic gameLogic, FoxHandCard handCard) {
        FoxCardConfig config = gameLogic.getConfig();
        if (triggerType == eFoxCardTriggerType.ADD && handCard == null) {
            //生成指定的点数和花色
            int point = Integer.valueOf(effectConfig.getParamsList().get(0));
            int color = Integer.valueOf(effectConfig.getParamsList().get(1));
            if (point == -1) {
                point = config.getRandomHelper().next(1, config.getPointToScoreMap().size() + 1);
            }
            if (color == -1) {
                color = config.getRandomHelper().next(1, FoxCardGameLogic.CARD_COLOR_NUM + 1);
            }
            List<Long> effectValues = new ArrayList<>();
            effectValues.add((long) point);
            effectValues.add((long) color);
            effectCard.setEffectValues(effectValues);
        } else if (triggerType == eFoxCardTriggerType.DROP) {
            int point = effectCard.getEffectValues().get(0).intValue();
            int color = effectCard.getEffectValues().get(1).intValue();
            int goldAdd = Integer.valueOf(effectConfig.getParamsList().get(2));

            //0表示没指定点数和花色
            int totalTimes = 0;
            for (FoxHandCard dropHandCard : gameLogic.getDropHandCards()) {
                if (config.isNotPointAndNotColorHandCard(dropHandCard.getReinforceEffect())) {//石头牌没有花色和点数
                    continue;
                }
                if (point != 0 && gameLogic.getHandCardNowPoint(dropHandCard) != point) {
                    continue;
                }
                if (color != 0 && (dropHandCard.getColor() != color && !config.isAllColorHandCard(dropHandCard.getReinforceEffect()))) {
                    continue;
                }
                totalTimes++;
            }
            goldAdd = goldAdd * totalTimes;
            if (goldAdd > 0) {
                gameLogic.goldChange(goldAdd, Collections.singletonList(effectCard), null, triggerType);
            }
        } else if (triggerType == eFoxCardTriggerType.ROUND_START) {
            int point = Integer.valueOf(effectConfig.getParamsList().get(0));
            int color = Integer.valueOf(effectConfig.getParamsList().get(1));
            if (point == -1) {
                point = config.getRandomHelper().next(1, config.getPointToScoreMap().size() + 1);
            }
            if (color == -1) {
                color = config.getRandomHelper().next(1, FoxCardGameLogic.CARD_COLOR_NUM + 1);
            }
            List<Long> effectValues = new ArrayList<>();
            effectValues.add((long) point);
            effectValues.add((long) color);
            effectCard.setEffectValues(effectValues);
        }
    }
}
